/*****************************************************************************************
 * FILE NAME: drv_flash                       COPYRIGHT (c) cos 2024
 * REVISION:  1.0.0                                     All Rights Reserved
 * DESCRIPTION:
 * =======================================================================================
 * UPDATE HISTORY:
 * REV      AUTHOR      DATE
 * v1.0.0   Tuxin       2024.10.14
 * DESCRIPTION OF CHANGE:
 ****************************************************************************************/
#ifndef __DRV_FLASH_H
#define __DRV_FLASH_H

//----------------------------------------------------------------------------------------
// @Project Includes
#include "typedefs.h"

//----------------------------------------------------------------------------------------
// @Global Macro Define in the module
#define FLASH_SIZE                (128*1024)/*MCU flash size 512K*/
#define FLASH_MAIN_SECTOR_SIZE	  (1*2048)/*the main flash sector size*/
#define FLASH_MAIN_SIZE           (128*1024)/*the main flash size*/

#define FLASH_EXTRA_SECTOR_SIZE   (1*2048)/*the ext flash sector size*/
#define FLASH_EXTRA_SIZE          (FLASH_SIZE-FLASH_MAIN_SIZE)/*the ext flash size*/
#define FLASH_EXTRA_START_ADDR    (FLASH_BASE + FLASH_MAIN_SIZE)/*the ext flash start addrss*/

/*
 * BOOT SIZE				12K
 * APP SIZE					100K
 * APP BACK SIZE		100K
 * OTA INFO SIZE 		4K
 * Parameter SIZE		4K
 */  
#define BOOT_SIZE	               	((uint32_t)16*1024)/*Boot size*/

#define DEVICE_MAIN_APP_ADDR      (FLASH_BASE + BOOT_SIZE)/*the app start address*/
#define DEVICE_MAIN_APP_SIZE      (100*1024)/*app size*/

//#define APP_BACK_ADDR_START 			(FLASH_BASE + BOOT_SIZE+DEVICE_MAIN_APP_SIZE)/*the back app start address*/
//#define APP_BACKUP_SIZE						(100*1024)/*back app size*/

#define OTA_CONFIG_ADDR						(DEVICE_MAIN_APP_ADDR+DEVICE_MAIN_APP_SIZE)
#define OTA_CONFIG_SIZE						(2*1024)

#define DEVICE_CONFIG_PRAM_ADDR   (OTA_CONFIG_ADDR + OTA_CONFIG_SIZE)
#define DEVICE_CONFIG_PRAM_SIZE   (2*1024)

#define EVENT_SAVE_ADDR				    (DEVICE_CONFIG_PRAM_ADDR + DEVICE_CONFIG_PRAM_SIZE)
#define EVENT_SAVE_SIZE						(8*1024)

//----------------------------------------------------------------------------------------
// @Global Type defines in the module

//----------------------------------------------------------------------------------------
// @Export global Variables declare in the module

//----------------------------------------------------------------------------------------
// @Export declaration of functions in the module

void drv_flash_init(void);
void drv_flash_read(uint8_t *pBuffer, uint32_t address,  uint16_t readLen);
bool_t drv_flash_write(uint8_t* pBuffer, uint32_t writeAddr, uint16_t writeLen);
#endif

// =======================================================================================
// End of file.
// =======================================================================================
